<?php

/*
=====================================================
 FluxBB - Delux Board Converstations (DBC)
-----------------------------------------------------
 http://dbc-forum.com/
 http://fluxbb.org/
-----------------------------------------------------
 Copyright (c) 2010,2011 FluxBB - Delux Board Conversations (DBC)
-----------------------------------------------------
 Предсловие: Данный скрипт (DBC) не является работой с нуля, то 
 есть ядром скрипта всё также остаётся FuxBB,но теперь в оболочке
 DBC.
=====================================================
*/

// Make sure no one attempts to run this script "directly"
if (!defined('DBC'))
	exit;

// Load the language file
require DBC_ROOT.'language/'.$admin_language.'/admin_plugin_pms_new.php';

// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('DBC_PLUGIN_LOADED', 1);

// If the "Show text" button was clicked
if (isset($_POST['show_text']))
{

	$en_pms = isset($_POST['enable_pms']) ? intval($_POST['enable_pms']) : 0;
	$en_pms = ($en_pms == 1) ? 1 : 0;
	$g_limit = isset($_POST['g_limit']) ? array_map('trim', $_POST['g_limit']) : array();
	$g_pm = isset($_POST['g_pm']) ? array_map('trim', $_POST['g_pm']) : array();
	$min_kolvo = isset($_POST['min_kolvo']) ? intval($_POST['min_kolvo']) : 0;

	$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$en_pms.'\' WHERE conf_name=\'o_pms_enabled\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
	$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$min_kolvo.'\' WHERE conf_name=\'o_pms_min_kolvo\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());

	$result = $db->query('SELECT g_id FROM '.$db->prefix.'groups ORDER BY g_id') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());

	while ($cur_group = $db->fetch_assoc($result))
		if ($cur_group['g_id'] > DBC_ADMIN && $cur_group['g_id'] != DBC_GUEST)
			if (isset($g_limit[$cur_group['g_id']]))
			{
				$g_lim = isset($g_limit[$cur_group['g_id']]) ? intval($g_limit[$cur_group['g_id']]) : 0;
				$g_p = (isset($g_pm[$cur_group['g_id']]) || $cur_group['g_id'] == DBC_ADMIN) ? 1 : 0;

				$db->query('UPDATE '.$db->prefix.'groups SET g_pm='.$g_p.', g_pm_limit='.$g_lim.' WHERE g_id='.$cur_group['g_id']) or error('Unable to update user group list', __FILE__, __LINE__, $db->error());
			}

	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
		require DBC_ROOT.'engine/cache.php';

	generate_config_cache();

	redirect(DBC_htmlspecialchars('admin_loader.php?plugin=AP_PMS_New.php'), $lang_admin_plugin_pms_new['Plugin redirect']);

}
else
{
	// Display the admin navigation menu
	generate_admin_menu($plugin);

	$cur_index = 1;

?>
	<div class="plugin blockform">

<table width="100%" height="38" border="0" cellpadding="0" cellspacing="0"><thead><tr>
<td align="left" width="28" class="bg_forum_title_left"><img src="engine/skins/images/spacer.gif" border="0"></td>
<td align="left" class="bg_forum_title_center"><span class="cat_title"><?php echo $lang_admin_plugin_pms_new['Plugin title'] ?></span></td>
<td align="center" width="28" class="bg_forum_title_right"><img src="engine/skins/images/spacer.gif" border="0"></td>
</tr></table>

<table class="forum_adv_table"  width="100%" border="0" cellpadding="0" cellspacing="0"><thead><tr>
<td align="left" class="forum_adv_tleft" width="2"><img src="engine/skins/images/spacer.gif" border="0"></td>
<td align="left" width="100%"><div class="forum_adv_c">

			<div class="inbox">
				<p><?php echo $lang_admin_plugin_pms_new['Explanation 1'] ?></p>
				<p><?php echo $lang_admin_plugin_pms_new['Explanation 2'] ?></p>
			</div>
<br/>
</div></td>
<td align="left" class="forum_adv_tright" width="2"><img src="engine/skins/images/spacer.gif" border="0"></td>
</td></tr></table>
<table width="100%" height="23" border="0" cellpadding="0" cellspacing="0"><thead><tr>
<td align="left" width="30" class="bg_forum_bott_left"><img src="engine/skins/images/spacer.gif" border="0"></td>
<td align="left" class="bg_forum_bott_center"><img src="engine/skins/images/spacer.gif" border="0"></td>
<td align="center" width="30" class="bg_forum_bott_right"><img src="engine/skins/images/spacer.gif" border="0"></td>
</tr></thead></table>

<table width="100%" height="38" border="0" cellpadding="0" cellspacing="0"><thead><tr>
<td align="left" width="28" class="bg_forum_title_left"><img src="engine/skins/images/spacer.gif" border="0"></td>
<td align="left" class="bg_forum_title_center"><span class="cat_title"><?php echo $lang_admin_plugin_pms_new['Form title'] ?></span></td>
<td align="center" width="28" class="bg_forum_title_right"><img src="engine/skins/images/spacer.gif" border="0"></td>
</tr></table>

<table class="forum_adv_table"  width="100%" border="0" cellpadding="0" cellspacing="0"><thead><tr>
<td align="left" class="forum_adv_tleft" width="2"><img src="engine/skins/images/spacer.gif" border="0"></td>
<td align="left" width="100%"><div class="forum_adv_c">

			<form id="example" method="post" action="<?php echo DBC_htmlspecialchars($_SERVER['REQUEST_URI']) ?>&amp;foo=<?php echo time() ?>"><br/>
				<div class="inform">
					<fieldset>
						<div class="login_info"><?php echo $lang_admin_plugin_pms_new['Legend1'] ?></div>
						<div class="infldset">
							<table class="aligntop" cellspacing="0">
								<tr>
									<td>
										<span><input type="checkbox" name="enable_pms" value="1" tabindex="<?php echo ($cur_index++) ?>"<?php echo ($DBC_config['o_pms_enabled'] == '1') ? ' checked="checked"' : '' ?> />&#160;&#160;<?php echo $lang_admin_plugin_pms_new['Q1'] ?></span>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
				</div>
<?php
if ($DBC_config['o_pms_enabled'] == '1')
{
?>
				<div class="inform">
					<fieldset>
						<div class="login_info"><?php echo $lang_admin_plugin_pms_new['Legend3'] ?></div>
						<div class="infldset">
							<table class="aligntop" cellspacing="0">
								<tr>
									<td>
										<span><input type="text" class="input_text" name="min_kolvo" value="<?php echo DBC_htmlspecialchars($DBC_config['o_pms_min_kolvo']) ?>"  tabindex="<?php echo ($cur_index++) ?>" size="10" maxlength="10" />&#160;&#160;<?php echo $lang_admin_plugin_pms_new['Q3'] ?></span>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
				</div>
				<div class="inform">
					<fieldset>
						<div class="login_info"><?php echo $lang_admin_plugin_pms_new['Legend2'] ?></div>
						<div class="infldset">
							<table class="aligntop" cellspacing="0">
							<thead>
								<tr>
									<th class="tcl" scope="col"><?php echo $lang_admin_plugin_pms_new['Group'] ?></th>
									<th class="tc2" scope="col"><?php echo $lang_admin_plugin_pms_new['Allow'] ?></th>
									<th scope="tcr"><?php echo $lang_admin_plugin_pms_new['Kolvo'] ?></th>
								</tr>
							</thead>
							<tbody>
<?php

	$result = $db->query('SELECT g_id, g_title, g_pm, g_pm_limit FROM '.$db->prefix.'groups ORDER BY g_id') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());

	while ($cur_group = $db->fetch_assoc($result))
		if ($cur_group['g_id'] > DBC_ADMIN && $cur_group['g_id'] != DBC_GUEST)
		{
?>
								<tr>
									<td class="tcl"><?php echo DBC_htmlspecialchars($cur_group['g_title']) ?></td>
									<td class="tc2"><input type="checkbox" name="g_pm[<?php echo $cur_group['g_id'] ?>]" value="1" tabindex="<?php echo ($cur_index++) ?>"<?php echo ($cur_group['g_pm'] == 1 ? ' checked="checked"' : '')?> /></td>
									<td class="tcr"><input type="text" class="input_text" name="g_limit[<?php echo $cur_group['g_id'] ?>]" value="<?php echo $cur_group['g_pm_limit'] ?>"  tabindex="<?php echo ($cur_index++) ?>" size="10" maxlength="10" /></td>
								</tr>
<?php
		}
?>
							</tbody>
							</table>
						</div>
					</fieldset>
				</div>
<?php
}
?>
				<p class="submitend"><input type="submit" class="fbutton" name="show_text" value="<?php echo $lang_admin_plugin_pms_new['Show text button'] ?>" tabindex="<?php echo ($cur_index++) ?>" /></p>
			</form>
<br/>
</div></td>
<td align="left" class="forum_adv_tright" width="2"><img src="engine/skins/images/spacer.gif" border="0"></td>
</td></tr></table>
<table width="100%" height="23" border="0" cellpadding="0" cellspacing="0"><thead><tr>
<td align="left" width="30" class="bg_forum_bott_left"><img src="engine/skins/images/spacer.gif" border="0"></td>
<td align="left" class="bg_forum_bott_center"><img src="engine/skins/images/spacer.gif" border="0"></td>
<td align="center" width="30" class="bg_forum_bott_right"><img src="engine/skins/images/spacer.gif" border="0"></td>
</tr></thead></table>
	</div>
<?php
}